package com.zhangmeng.online.exam.entity;

import com.zhangmeng.online.exam.entity.baseEntity.BaseEntity;
import lombok.*;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * @author zm
 * @date 2025/2/28 14:45
 * @version: 1.0
 */
@NoArgsConstructor
@ToString(exclude = {"users","permissions"})
@Getter
@Setter
@AllArgsConstructor
@Entity
@Table(name = "role")
public class Role extends BaseEntity<Long> {

    @Getter
    public enum Type {

        STUDENT("学生"),//学生
        TEACHER("教师"),//教师
        ADMIN("管理员");//管理员

        private final String desc;

        Type(String desc) {
            this.desc = desc;
        }

    }

    @Column(name = "type")
    @Enumerated(EnumType.ORDINAL)
    private Type type;

    private String name;

    private String description;

    @ManyToMany(mappedBy = "roles",targetEntity = User.class)
    private Set<User> users = new HashSet<>();

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "role_permission", joinColumns = @JoinColumn(name = "role_id"), inverseJoinColumns = @JoinColumn(name = "permission_id"))
    private Set<Permission> permissions = new HashSet<>();

}
